package com.bensonbasement.snorflux.utils;

import java.io.Serializable;

import org.python.core.Py;
import org.python.core.PyObject;

public class Coords /*extends PyObject*/ implements Serializable {
	
	public static final Coords ORIGIN = new Coords(0,0);
	
	private final int x;
	private final int y;
	
	public Coords(int x, int y) {
		this.x = x;
		this.y = y;
	}

	public int getX() {
		return this.x;
	}

	public int getY() {
		return this.y;
	}

	public Coords getNeighbor(Direction dir) {
		return this.plus(dir.getCoords());
	}

	public Coords plus(Coords otherCoords) {
		int newX = this.x+otherCoords.getX();
		int newY = this.y+otherCoords.getY();
		return new Coords(newX,newY);
	}

	public Coords minus(Coords otherCoords) {
		return this.plus(otherCoords.negate());
	}

	public Coords negate() {
		return new Coords(-this.x,-this.y);
	}
	
	public Coords times(int factor) {
		return new Coords(this.x*factor,this.y*factor);
	}
	
	public Coords integerDivide(int denominator) {
		return new Coords(this.x/denominator,this.y/denominator);
	}
	
	@Override
	public String toString() {
		return "("+this.x+","+this.y+")";
	}
	
	@Override
	public boolean equals(Object other) {
		if (other.getClass() == this.getClass()) {
			Coords otherCoords = (Coords) other;
			return (this.x == otherCoords.x && this.y == otherCoords.y);
		}
		else {
			return false;
		}
	}
	
	@Override
	public int hashCode() {
		return this.toString().hashCode();
	}
	
	
//	// JYTHON CONVENIENCE STUFF
//	@Override
//	public PyObject __add__(PyObject other) {
//		if (other instanceof Coords) {
//			return this.plus((Coords) other);
//		}
//		else {
//			return null;
//		}
//	}
//	
//	@Override
//	public PyObject __neg__() {
//		return this.negate();
//	}
//	
//	@Override
//	public PyObject __sub__(PyObject other) {
//		if (other instanceof Coords) {
//			return this.minus((Coords) other);
//		}
//		else {
//			return null;
//		}
//	}
//	
//	@Override
//	public PyObject __eq__(PyObject other) {
//		if (this.equals(other)) {
//			return Py.True;
//		}
//		else {
//			return Py.False;
//		}
//	}
//	
//	@Override
//	public PyObject __ne__(PyObject other) {
//		if (this.equals(other)) {
//			return Py.False;
//		}
//		else {
//			return Py.True;
//		}
//	}
}
